﻿using AuthCenter.Common;
using B.S.BasicData.ErrorCode;
using B.S.BasicData.Read.Apilication.Common.login;
using B.S.BasicData.Read.DTOS;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;

namespace B.S.BasicData.Read.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class loginController : ControllerBase
    {
        private readonly IMediator mediator;
        private readonly ILogger<loginController> logger;

        public loginController(IMediator mediator,ILogger<loginController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ApiResult<UserDTO>> GetloginHandle(GetloginCommon request)
        {
            try
            {


                logger.LogInformation("用户登录成功");

                //string numberstr = "123456";
                //int number1 = numberstr.ToInt32();

                //int number=Convert.ToInt32(numberstr);
                //string birth = "130529200605062614".getBirthByCarid();

                var userid = HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
                var username = HttpContext.User.FindFirst(ClaimTypes.Name)?.Value;
                var roleName=HttpContext.User.FindFirst(ClaimTypes.Role)?.Value;
                var customerValue=HttpContext.User.FindFirst("CustomClaimType")?.Value;

                var key=HttpContext.User.FindFirst("Key")?.Value;


                return mediator.Send(request);
            }
            catch (Exception ex)
            {
                logger.LogError("用户登录异常"+ex.Message);
                throw;
            }
         
        }

       


        }
}
